package com.objetdirect.gwt.umldrawer.client;


import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.DeferredCommand;
import com.google.gwt.user.client.ui.ResizeComposite;
import com.gwtext.client.core.Margins;
import com.gwtext.client.core.RegionPosition;
import com.gwtext.client.widgets.Panel;
import com.gwtext.client.widgets.layout.BorderLayout;
import com.gwtext.client.widgets.layout.BorderLayoutData;
import com.gwtext.client.widgets.layout.FitLayout;
import com.gwtext.client.widgets.tree.TreePanel;

@SuppressWarnings("deprecation")
public class UMLDrawer extends ResizeComposite {

	public Panel getUMLDrawerPage() {
		
		Panel panel = new Panel();
		panel.setBorder(false);
		panel.setTitle("Online Professional Design UML Drawer");
		panel.setWidth(1360);
		panel.setHeight(565);
		panel.setPaddings(0);
		panel.setCollapsible(true);
		panel.setTitleCollapse(true);
		panel.setAutoScroll(true);
		panel.setLayout(new FitLayout());

		Panel borderPanel = new Panel();
		borderPanel.setLayout(new BorderLayout());

		// add east panel
		Panel chatPanel = new Panel();
		chatPanel.setTitle("Chatting Panel");
		chatPanel.setCollapsible(true);
		chatPanel.setCollapsed(true);
		chatPanel.setTitleCollapse(false);
		chatPanel.setWidth(225);

		BorderLayoutData chatData = new BorderLayoutData(RegionPosition.EAST);
		chatData.setSplit(true);
		chatData.setMinSize(225);
		chatData.setMaxSize(400);
		chatData.setMargins(new Margins(0, 0, 0, 0));

		borderPanel.add(chatPanel, chatData);

		/**
		 * Project Panel
		 */
		Panel projectPanel = new Panel();
		projectPanel.setTitle("Project Panel");
		projectPanel.setCollapsed(true);
		projectPanel.setCollapsible(true);
		projectPanel.setWidth(200);
		projectPanel.setAutoScroll(true);

		BorderLayoutData projectData = new BorderLayoutData(RegionPosition.WEST);
		projectData.setSplit(true);
		projectData.setMinSize(200);
		projectData.setMaxSize(400);
		projectData.setMargins(new Margins(0, 0, 0, 0));
		
		borderPanel.add(projectPanel, projectData);
		
		// Adding Tree Panel To Project Panel
		TreePanel openProject = new TreePanel();
		openProject.setRootNode(new OpenProjectTree().getOpenProjectTree());
		openProject.setHeight(240);
		openProject.setAutoScroll(true);
		projectPanel.add(openProject);
		
		/**
		 * Team Members Panel
		 */
		Panel teamMembersPanel = new Panel();
		teamMembersPanel.setTitle("Team Members");
		teamMembersPanel.setAutoScroll(true);
		teamMembersPanel.setTitleCollapse(true);
		
		projectPanel.add(teamMembersPanel);

		Panel centerPanel = new Panel();
		DrawerContainer drawerContainer = new DrawerContainer();
		forceDrawerResize(drawerContainer);
		drawerContainer.asWidget();
		centerPanel.add(drawerContainer);
		
		borderPanel.add(centerPanel, new BorderLayoutData(RegionPosition.CENTER));

		panel.add(borderPanel);
		
		DrawerToolbar drawerToolbar = new DrawerToolbar();
		panel.setTopToolbar(drawerToolbar.getToolBar());
		
		return panel;
	}
	
	private void forceDrawerResize(final DrawerContainer drawerContainer) {
		DeferredCommand.addCommand(new Command() {
			@Override
			public void execute() {
				drawerContainer.onResize();
			}
		});
	}
}
